package com.itheima.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.bean.Orders;
import com.itheima.common.R;
import com.itheima.dto.ParamPageDto;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/order")
public class OrdersController {
    @Autowired
    private OrderService orderService;
    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders, HttpSession session){
        if (orderService.add(orders, session)>0){
            return R.success("添加订单成功！");
        }
        return R.error("添加订单失败！");
    }
    @GetMapping("/page")
    public R page(ParamPageDto paramPage){
        System.out.println(paramPage);
        IPage<Orders> page = orderService.findPage(paramPage,null);
        if (page!=null){
            return R.success(page);
        }
        return R.error("查询失败！");
    }
    @PutMapping
    public R update(@RequestBody Orders orders){
        if (orderService.Update(orders)>0){
            return R.success("更新成功！");
        }
        return R.error("更新失败！");
    }
    @GetMapping("/userPage")
    public R userPage(ParamPageDto paramPage,HttpSession session){
        IPage<Orders> page = orderService.findPage(paramPage,session);
        return R.success(page);
    }
    @PostMapping("/again")
    public R again(@RequestBody Orders orders){
        return R.success(orderService.again(orders));
    }
}
